package asmilk.astest.web.config;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

@WebListener
public class WebConfigListener implements ServletContextListener {

	private static final Logger LOG = LoggerFactory.getLogger(WebConfigListener.class);

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		//System.setProperty("https.protocols", "TLSv1");
		//System.setProperty("jsse.enableSNIExtension", "false");
		this.installRootLoggerHandler();
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		this.uninstallRootLoggerHandler();
	}

	private void installRootLoggerHandler() {
		SLF4JBridgeHandler.removeHandlersForRootLogger();
		SLF4JBridgeHandler.install();
		LOG.info("Installed root logger handler.");
	}

	private void uninstallRootLoggerHandler() {
		SLF4JBridgeHandler.uninstall();
		LOG.info("Uninstalled root logger handler.");
	}

}
